package com.diors.game.example.server.xmldata;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.diors.game.engine.arpg.npc.model.NpcModel;

/**
 * NPC Data类
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-28
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
@XmlRootElement(name = "npcs")
@XmlAccessorType(XmlAccessType.FIELD)
public class NpcData {

	@XmlElement(name = "npc")
	List<NpcModel> list;
	
	private Map<Integer, NpcModel> npcs = new HashMap<Integer, NpcModel>();
	
	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		npcs.clear();
		for(NpcModel npc : list)
		{
			npcs.put(npc.getId(), npc);
		}
			
		list = null;
		XmlDataManager.log.info("loading NpcData size:" + npcs.size());
	}
	
	public NpcModel get (int id)
	{
		return npcs.get(id);
	}
}
